﻿using MengLin.OOP.DesignPattern.FlyWeightPattern.BasicCode.Abstract;
using MengLin.OOP.DesignPattern.FlyWeightPattern.BasicCode.Implements;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.FlyWeightPattern.BasicCode.Factory
{
    /// <summary>
    /// 享元工厂
    /// </summary>
    public class FlyweightFactory
    {
        private Hashtable flyweights = new Hashtable();

        /// <summary>
        /// Ctor
        /// </summary>
        public FlyweightFactory()
        {
            flyweights.Add("X", new ConcreteFlyweight());
            flyweights.Add("Y", new ConcreteFlyweight());
            flyweights.Add("Z", new ConcreteFlyweight());
        }

        /// <summary>
        /// 得到对象
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public AbstractFlyweight GetFlyweight(string key)
        {
            return ((AbstractFlyweight)flyweights[key]);
        }
    }
}
